<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\CustomerServer;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;

class CustomerController extends Controller
{
    //客户管理

    public function __construct() {
        $this->server = new CustomerServer();
    }

    /**
     * 添加客户
     * @param Request $request
     */
    public function addCustomer(Request $request){
        $id = $request->input('id');
        $customer_name = $request->input('customer_name');
        $customer_address = $request->input('customer_address');
        $customer_phone = $request->input('customer_phone');
        $another_name = $request->input('another_name');
        $province = $request->input('province');
        $city = $request->input('city');
        $county = $request->input('county');
        $town = $request->input('town');
        $village = $request->input('village');
        $team = $request->input('team');
        $wheat = $request->input('wheat');
        $res = $this->server->addCustomerServer($id,$customer_name,$customer_address,$customer_phone,$another_name,$province,$city,$county,$town,$village,$team,$wheat);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取客户列表
     */
    public function getCustomerList(Request $request){
        // 获取查询条件
        $params = $request->only(['customer_name', 'customer_phone','another_name','province','city','county','town','village','team']);
        $per_page = $request->input('per_page');
        $res = $this->server->getCustomerListServer($params,$per_page);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    public function getCustomerInfo(Request $request){
        $id = $request->input('id');
        $res = $this->server->getCustomerInfoServer($id);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

}
